perm filename SAITG1.FAI[S,AIL] blob
sn#193085 filedate 1975-12-15 generic text, type T, neo UTF8
SEARCH HDRFIL
COMPIL(TG1,<SIN$,COS$,SIND$,COSD$,SQRT$,RAN$>,<TRIGINI,X22,.RSEED>,<SIN, SQRT ROUTINES>)
BEGIN SIN$
AA←13
BB←14
CC←15
HERE(COSD$) ;ENTRY TO COSINE DEGREES ROUTINE.
MOVE BB,-1(P) ;PICK UP THE ARG.
FADR BB,CD1 ;ADD 90 DEGREES.
JRST CONVER ;CONVERT TO RADIANS
HERE(SIND$) ;ENTRY TO SINE DEGREES ROUTINE.
MOVE BB,-1(P) ;PICK UP THE ARG.
CONVER: FDVR BB,SCD1 ;CONVERT TO RADIANS
JFOV .+1 ;SUPPRESS ERROR MESSAGE ON UNDERFLOW.
JRST S1 ;ENTER SINE ROUTINE.
HERE(COS$) ;ENTRY TO COSINE RADIANS ROUTINE.
MOVE BB,-1(P) ;PICK UP THE ARG.
FADR BB,PIOT ;ADD PI/2.
JRST S1 ;ENTER SINE ROUTINE.
HERE(SIN$) ;ENTRY TO SINE RADIANS ROUTINE.
MOVE BB,-1(P) ;PICK UP THE ARG.
S1: MOVEM BB,-1(P) ;SAVE THE ARG.
MOVMS BB ;GET ABS OF ARG.
CAMG BB,SP2 ;SIN(X)=X IF X LESS THAN 2↑-9.
JRST S3A ;EXIT WITH ARG. IN B.
FDV BB,PIOT ;DIVIDE X BY PI/2.
CAMG BB,ONE ;IS X/(PI/2) LESS THAN 1.0 ?
JRST S2 ;YES,ARG IN 1ST QUADRANT ALREADY.
MULI BB,400 ;NO,SEPARATE FRACTION AND EXP.
ASH CC,-202(BB) ;GET X MODULO 2PI.
JFOV .+1 ;SUPRESS ERROR MESSAGE FROM OVTRAP.
MOVEI BB,200 ;PREPARE FLOATING FRACTION.
ROT CC,3 ;SAVE THREE BITS TO DETERMINE QUADRANT.
LSHC BB,33 ;ARGUMENT NOW IN THE RANGE (-1,1).
FAD BB,SP3 ;NORMALIZE THE ARGUMENT.
JUMPE CC,S2 ;REDUCED TO 1ST QUAD IF BITS 000.
TLCE CC,1000 ;SUBTRACT 1.0 FROM ARG IF BITS ARE
FSB BB,ONE ;001 OR 011.
TLCE CC,3000 ;CHECK FOR FIRST QUADRANT, 001.
TLNN CC,3000 ;CHECK FOR THIRD QUADRANT, 010.
MOVNS BB ;001,010.
S2: SKIPGE -1(P) ;CHECK SIGN OF ORIGINAL ARG.
MOVNS BB ;SIN(-X)=-SIN(X).
MOVEM BB,-1(P) ;STORE REDUCED ARG.
FMPR BB,BB ;CALCULATE X↑X
MOVE AA,SC9 ;GET 1ST CONSTANT.
FMP AA,BB ;MULTIPLY BY X↑2
FAD AA,SC7 ;ADD IN NEXT CONSTANT.
FMP AA,BB ;MULTIPLY BY X↑2.
FAD AA,SC5 ;ADD IN NEXT CONSTANT.
FMP AA,BB ;MULTIPLY BY X↑2.
FAD AA,SC3 ;ADD IN NEXT CONSTANT.
FMP AA,BB ;MULTIPLY BY X↑2.
FAD AA,PIOT ;ADD IN LAST CONSTANT.
S2B: FMPR AA,-1(P) ;MULTIPLY BY X.
SKIPA 1,AA ;ANSWER IN 1
S3A: MOVE 1,-1(P) ;ANSWER IN 1.
SUB P,X22
JRST @2(P)
SC3: 577265210372
SC5: 175506321276
SC7: 606315546346
SC9: 164475536722
SP2: 170000000000
SP3: 0
CD0I90.0
SCD1: 206712273406
PIOT: 201622077325
ONE: 1.0
BEND SIN$
BEGIN SQRT$
AA←13
BB←14
F←15
HERE(SQRT$) ;ENTRY TO SQUARE ROOT ROUTINE
SKIPG BB,-1(P) ;PICK UP ARG. CHECK IF GREATER THAN 0
JRST SQRT4 ;NO, HANDLE NON-POSITIVE ARGUMENT
MOVEI AA,0 ;GET EXPONENT TO AA
LSHC AA,=9
SUBI AA,201 ;GET TRUE EXPONENT + 1
ROT AA,-1 ;DIVIDE BY 2
JUMPL AA,SQRT3 ;JUMP IF FRACTION GREATER THAN .5
LSH BB,-=9 ;RESTORE POSITION OF FRACTION IN BB
FSC BB,177 ;AND FIX UP EXPONENT .25 LESS THAN F LESS THAN .5
MOVEM BB,F ;SAVE FRACTION
FMPRI BB,200640
FADRI BB,177465
SQRT1: MOVE 1,F ;1ST ITERATION OF NEWTON
FDV 1,BB ; F/APPROX
FAD BB,1 ; APPROX + F/APPROX
FSC BB,-1 ; .5*( APPROX + F/APPROX)
MOVE 1,F ;2ND ITERATION OF NEWTON
FDV 1,BB ; F/APPROX
FADR 1,BB ; APPROX + F/APPROX
FSC 1,(AA) ;HALVE AND SCALE EXPONENT
EXIT: SUB P,X22
JRST @2(P)
SQRT3: LSH BB,-=9 ;RESTORE POSITION OF FRACTION IN BB
FSC BB,200 ;AND FIX UP EXPONENT .5 LESS THAN= F LESS THAN 1
MOVEM BB,F ;SAVE FRACTION
FMPRI BB,200450
FADRI BB,177660
JRST SQRT1 ;NOW GO ITERATE
SQRT4: JUMPE BB,ZERO
ERR <SQRT: Negative argument - 0 returned>,1
ZERO: MOVEI 1,0 ;HERE ON NON-POSITIVE ARG. RETURN ZERO
JRST EXIT
BEND SQRT$
BEGIN RAN$
AA←13
BB←14
INTERNAL RAN$
RAN$:
MOVE AA,-1(P) ;IF ARG = 0 THEN
JUMPE AA,R1 ;USE PREVIOUS RANDOM NO.
TLZ AA,760000 ;OTHERWISE MASK 5 BITS
MOVEM AA,.RSEED ;AND STORE NEW NO.
R1: MOVE AA,K ;GET K [14**29(MOD2**31 -1)]
MUL AA,.RSEED ;MULTIPLY WITH LAST RANDOM NUMBER
ASHC AA,4 ;SEPARATE RESULT IN TWO 31 BIT WORDS
LSH BB,-4
ADD AA,BB ;ADD THEM TOGETHER
TLZE AA,760000 ;SKIP IF RESULT LESS THAN 31 BITS
ADDI AA,1
MOVEM AA,.RSEED ;STORE NEW RN IN INTEGER MODE
HLRZ 1,AA ;CONVERT TO FP IN TWO STEPS IN
FSC 1,216 ;ORDER TO LOOSE NO LOW ORDER
HRLI AA,0 ;BITS
FSC AA,174
FAD 1,AA
SUB P,X22
JRST @2(P) ;EXIT
K: =630360016 ;14**29(MOD 2**31 -1)
BEND RAN$
ENDCOM(TG1)
END